package org.liujing.jsw.client.ui;

import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.event.logical.shared.*;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.shared.*;
import com.google.gwt.event.dom.client.*;
import java.util.logging.*;

@SuppressWarnings("deprecation")
public class GWTWidgetWrapper extends Widget implements RequiresResize{
	private static Logger log = Logger.getLogger("client.GWTWidgetWrapper");
	private JComponent target;
	
	public GWTWidgetWrapper(JComponent target){
		this.target = target;
		setElement(target.getDomElement());
	}
	
	public <H extends EventHandler> HandlerRegistration addDomHandler(H handler, DomEvent.Type<H> type){
		return super.addDomHandler(handler, type);
	}
	
	public void onResize(){
		log.info("onResize ");
		Widget w = getParent();
		Element el = w.getElement();
		//Element pel = el.getOffsetParent();
		log.info("onResize "+ this.getClass().getName() + ", " + el.getClientWidth()+ ", " + el.getClientHeight());
		target.setSize(new Dimension(el.getClientWidth(), el.getClientHeight()));		
	}
}
